package com.xiaoshuidi.cloud.module.rooms.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.area.vo.RoomProvinceCityVO;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomProvinceCityMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomProvinceCity;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author sampson
 * create 2023/12/25
 * email  sampson.wang@ixiaoshuidi.com
 */
@Repository
@RequiredArgsConstructor
public class RoomProvinceCityRepository extends ServiceImpl<RoomProvinceCityMapper, RoomProvinceCity> {

    public List<RoomProvinceCityVO> getProvince(){
        LambdaQueryWrapper<RoomProvinceCity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomProvinceCity::getDeleted, 0);
        List<RoomProvinceCityVO> list = this.baseMapper.distinct(wrapper,"province","province_name");
        return list;
    }

    public List<RoomProvinceCityVO> getCity(String provinceName) {
        LambdaQueryWrapper<RoomProvinceCity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomProvinceCity::getProvinceName,provinceName);
        List<RoomProvinceCityVO> list = this.baseMapper.get(wrapper,"city_name");
        return list;
    }
}
